#!/bin/bash


user_directory=$HOME

echo '处理 mysql'
echo '-------------------'

# 运行起来mysql
echo "运行 mysql"
docker run -p 3307:3306 --name mysql \
-v /home/lighthouse/docker_data/mysql/log:/var/log/mysql \
-v /home/lighthouse/docker_data/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root  \
-d mysql:5.7

# 将容器内的配置文件拷贝到指定目录：
echo "将容器内的配置文件拷贝到指定目录："
# docker container cp mysql:/etc/mysql /home/lighthouse/docker_data/mysql

docker container cp mysql:/etc/mysql/. /home/lighthouse/docker_data/mysql/conf

# mv /home/lighthouse/docker_data/mysql/mysql /home/lighthouse/docker_data/mysql/conf

echo "docker stop mysql"
docker stop mysql

echo "docker rm mysql"
docker rm mysql

# echo "再次运行 mysql"
docker run -p 3307:3306 --name mysql \
--restart=always \
-v /home/lighthouse/docker_data/mysql/log:/var/log/mysql \
-v /home/lighthouse/docker_data/mysql/data:/var/lib/mysql \
-v /home/lighthouse/docker_data/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root  \
-d mysql:5.7

